package com.ndp.fb.fbagent.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.fbagent.service.ProductCatalogFBService;
import com.ndp.fb.model.fbagent.param.product.ProductCatalogParam;
import com.ndp.fb.model.fbagent.param.product.ProductCatalogPixelParam;
import com.ndp.fb.model.fbagent.result.FacebookResult;
import com.ndp.fb.model.fbagent.result.businesses.UserpermissionsResult;
import com.ndp.fb.model.fbagent.result.productfeed.FBProductCatalog;
import com.restfb.Parameter;

import java.util.Arrays;
import java.util.List;

/**
 * Created by Evan on 2016/4/15.
 */
@Service
public class ProductCatalogFBServiceImpl extends AbstractFBagentService implements ProductCatalogFBService {


    @Override
    public List<FBProductCatalog> getAllCatalogFromBM(ProductCatalogParam param) {
        String url = "/" + param.getBusinessId() + "/product_catalogs";
        Parameter[] parameters = this.adapterArray(param);
        FacebookResult<FBProductCatalog> result = syncFetchFacebookResult(url, param.getAccessToken(), Arrays.asList(parameters), true, 0, 1000, FBProductCatalog.class);
        return result.getObjects();
    }

    @Override
    public void sendToFB(ProductCatalogParam param) {
        String url = "/" + param.getBusinessId() + "/product_catalogs";
        Parameter[] parameters = this.adapterArray(param);
        makePostRequest(url, param.getAccessToken(), parameters);
    }

    @Override
    public void bindPixelWithCatalog(ProductCatalogPixelParam param)
    {
        String url = "/" + param.getProductCatalogId() + "/external_event_sources";
        Parameter[] parameters = this.adapterArray(param);
        makePostRequest(url, param.getAccessToken(), parameters);
    }

//    @Override
//    public void catalogChecks(ProductCatalogPixelParam param) {
//        String url = "/" + param.getProductCatalogId() + "/product_ads_status_checks";
//        Parameter[] parameters = this.adapterArray(param);
//        makeGetRequest(url, param.getAccessToken(), parameters);
//    }
}
